<?php

declare(strict_types=1);

namespace App\Model;

use Carbon\Carbon;
use Qbhy\HyperfAuth\Authenticatable;

/**
 * @property int $id 主键
 * @property string $username 用户名
 * @property string $nickname 昵称
 * @property string $password 密码
 * @property string $sex 性别
 * @property string $avatar 头像
 * @property string $email 邮箱
 * @property string $mobile 手机
 * @property int $level 等级
 * @property string $birthday 生日
 * @property string $money 余额(元)
 * @property int $score 积分
 * @property string $last_time 登录时间
 * @property string $last_ip 登录ip
 * @property string $join_time 注册时间
 * @property string $join_ip 注册ip
 * @property string $token token
 * @property int $created_by 添加人
 * @property Carbon $created_at 创建时间
 * @property Carbon $updated_at 更新时间
 * @property int $role 角色
 * @property int $status 禁用
 * @property int $updated_by 修改人
 * @property int $sort_number 排序
 */
class User extends Model implements Authenticatable
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'users';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'username', 'nickname', 'password', 'sex', 'avatar', 'email', 'mobile', 'level', 'birthday', 'money', 'score', 'last_time', 'last_ip', 'join_time', 'join_ip', 'token', 'created_by', 'created_at', 'updated_at', 'role', 'status', 'updated_by', 'sort_number'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'level' => 'integer', 'score' => 'integer', 'created_by' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'role' => 'integer', 'status' => 'integer', 'updated_by' => 'integer', 'sort_number' => 'integer'];

    public function getId()
    {
        // 返回用户id
        return $this->id;
        // TODO: Implement getId() method.
    }

    public static function retrieveById($key): ?Authenticatable
    {
        // 通过id查找用户
        return self::query()->find($key);
        // TODO: Implement retrieveById() method.
    }
}
